package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RxSegment;
import com.ruoyi.system.service.IRxSegmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 规律段Controller
 *
 * @author hjf
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/hmk/segment")
public class RxSegmentController extends BaseController {
    @Autowired
    private IRxSegmentService rxSegmentService;

    /**
     * 查询规律段列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:segment:list')")
    @GetMapping("/list")
    public TableDataInfo list(RxSegment rxSegment) {
        startPage();
        List<RxSegment> list = rxSegmentService.selectRxSegmentList(rxSegment);
        return getDataTable(list);
    }


    @GetMapping("/simpleList")
    public AjaxResult simpleList(RxSegment rxSegment) {
        List<RxSegment> list = rxSegmentService.selectRxSegmentList(rxSegment);
        return AjaxResult.success(list);
    }

    /**
     * 导出规律段列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:segment:export')")
    @Log(title = "规律段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RxSegment rxSegment) {
        List<RxSegment> list = rxSegmentService.selectRxSegmentList(rxSegment);
        ExcelUtil<RxSegment> util = new ExcelUtil<RxSegment>(RxSegment.class);
        util.exportExcel(response, list, "规律段数据");
    }

    /**
     * 获取规律段详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:segment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rxSegmentService.selectRxSegmentById(id));
    }

    /**
     * 新增规律段
     */
    @PreAuthorize("@ss.hasPermi('hmk:segment:add')")
    @Log(title = "规律段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RxSegment rxSegment) {
        return toAjax(rxSegmentService.insertRxSegment(rxSegment));
    }

    /**
     * 修改规律段
     */
    @PreAuthorize("@ss.hasPermi('hmk:segment:edit')")
    @Log(title = "规律段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RxSegment rxSegment) {
        return toAjax(rxSegmentService.updateRxSegment(rxSegment));
    }

    /**
     * 删除规律段
     */
    @PreAuthorize("@ss.hasPermi('hmk:segment:remove')")
    @Log(title = "规律段", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rxSegmentService.deleteRxSegmentByIds(ids));
    }
}
